import machine ,time,_thread
from machine import Pin, PWM,SoftI2C
#使用GY530激光测距 Tof测距，使用i2c通讯
#代码需初始化I2c后使用
#暂不清楚输出数据类型
readA=0
readAL=1
readAR=2
readB=3
readBL=4
readBR=5
#此次为i2c通讯地址，测试时查询并填入
#register为要读取的寄存器地址,2为读取的寄存器长度，查询数据后填入
def readA(register):
    readA_reurn=i2c.readfrom(readA,register,2)
    print(readA_reurn)
    return readA_reurn
#前视雷达
def readAL(register):
    readAL_reurn=i2c.readfrom(readAL,register,2)
    print(readAL_reurn)
    return readAL_reurn
#左视雷达
def readAR(register):
    readAR_reurn=i2c.readfrom(readAR,register,2)
    print(readAR_reurn)
    return readAR_reurn
#右视雷达
def readB(register):
    readB_reurn=i2c.readfrom(readB,register,2)
    print(readB_reurn)
    return readB_reurn
#后视雷达
def readBL(register):
    readBL_reurn=i2c.readfrom(readBL,register,2)
    print(readBL_reurn)
    return readBL_reurn
#左后视雷达
def readBR(register):
    readBR_reurn=i2c.readfrom(readBR,register,2)
    print(readBR_reurn)
    return readBR_reurn
#右后视雷达
def radar_use_LR(value):
        if value==0:
            _thread.start_new_thread(readAL,('0x00',))
            _thread.start_new_thread(readAR,('0x00',))
            _thread.start_new_thread(readBL,('0x00',))
            _thread.start_new_thread(readBR,('0x00',))
        if value==1:
            print('radar unuse')
            _thread.exit()

def radar_use_HB(value):
    if value==0:
        _thread.start_new_thread(readA,('0x00',))
        _thread.start_new_thread(readB,('0x00',))
    if value == 1:
        _thread.exit()

    
